/**
 * Class: Activity
 *
 * Purpose: Add dynamic actions to Particles
 *
 * Created: Mar 6, 2010 @ 10:15:34 AM
 * @author Ken
 */
package org.openfantasia.ps.particle;

import org.openfantasia.ps.modifier.behaviors.Timeframe;

public abstract class Activity {

	protected Timeframe timeframe;


	public Activity() {
	}


	public Activity(Double start, Double end) {
		this.timeframe = new Timeframe(start, end);
	}


	public Activity(Timeframe timeframe) {
		this.timeframe = timeframe;
	}


	public Activity(Activity that) {
		copy(that);
	}


	public void copy(Activity that) {
		this.timeframe = that.timeframe.copy();
	}


	public abstract void action(Particle particle, double time);


	public boolean isActive(Particle particle, double time) {
		return (timeframe == null) || timeframe.isActive(particle, time);
	}


	public double getActivityTime(Particle particle, double time) {
		if ((timeframe != null) && timeframe.isActive(particle, time)) {
			return timeframe.getInternalTime(time);
		}
		return 0;
	}


	public Timeframe getTimeframe() {
		return timeframe;
	}


	public void setTimeframe(Double start, Double end) {
		this.timeframe = new Timeframe(start, end);
	}


	public void setTimeframe(Timeframe timeframe) {
		this.timeframe = timeframe;
	}
}
